package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value = "/api/album/category")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {

    @Autowired
    private BaseCategoryService baseCategoryService;

	@Operation(summary = "根据一级分类id查询标签属性")
	@GetMapping("/findAttribute/{category1Id}")
	public Result findAttribute(@PathVariable Long category1Id){
		//调用服务层方法
		//属性和属性值关系是一对多，再mybatis中配置一对多关系映射
		List<BaseAttribute> baseAttributeList = baseCategoryService.findAttribute(category1Id);
		return Result.ok(baseAttributeList);
	}

    @Operation(tags = "查询所有分级数据")
    @GetMapping("/getBaseCategoryList")
    public Result getBaseCategoryList() {
        //	调用服务层方法:
        List<JSONObject> list = this.baseCategoryService.getBaseCategoryList();
        //	返回数据
        return Result.ok(list);
    }

    /**
     * 根据三级分类Id 获取到分类数据
     * @param category3Id
     * @return
     */
    @GetMapping("/getCategoryView/{category3Id}")
    public Result<BaseCategoryView> getCategoryView(@PathVariable Long category3Id){
        //	调用服务层方法;
        BaseCategoryView baseCategoryView = baseCategoryService.getCategoryView(category3Id);
        //	返回数据
        return Result.ok(baseCategoryView);
    }
    /**
     * 根据一级分类Id获取到分类数据
     * @param category1Id
     * @return
     */
    @Operation(summary = "根据一级分类Id获取到分类数据")
    @GetMapping("/getBaseCategoryList/{category1Id}")
    public Result getBaseCategoryList(@PathVariable Long category1Id){
        //	调用服务层方法;
        JSONObject category1 = baseCategoryService.getBaseCategoryList(category1Id);
        //	返回数据
        return Result.ok(category1);
    }
    @Operation(summary = "根据一级分类Id查询三级分类数据")
    @GetMapping("findTopBaseCategory3/{category1Id}")
    public Result findTopBaseCategory3(@PathVariable Long category1Id){
        //	调用服务层方法;
        List<BaseCategory3> baseCategory3List = baseCategoryService.findTopBaseCategory3(category1Id);
        //	返回数据
        return Result.ok(baseCategory3List);
    }
    @Operation(summary = "获取全部一级分类")
    @GetMapping("/findAllCategory1")
    public Result<List<BaseCategory1>> findAllCategory1(){
        //	查询所有数据
        return Result.ok(baseCategoryService.list());
    }

}

